package com.rays.gank.ui.activity

import android.content.Intent
import android.os.Bundle
import androidx.core.app.ActivityOptionsCompat
import com.rays.gank.R
import kotlinx.coroutines.*

/**
 * Created by Rays on 2021/1/21.
 */
class SplashActivity : BaseActivity() {
    override fun getLayoutResId() = 0

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        // 后台返回时可能启动这个页面 http://blog.csdn.net/jianiuqi/article/details/54091181
        if (intent.flags and Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT != 0) {
            finish()
            return
        }
        toMain()
    }

    override fun initView(savedInstanceState: Bundle?) {

    }

    private fun toMain() = launch {
        delay(1000)
        val options = ActivityOptionsCompat.makeCustomAnimation(
            this@SplashActivity,
            R.anim.screen_zoom_in,
            R.anim.screen_zoom_out
        ).toBundle()
        startActivity(Intent(this@SplashActivity, MainActivity::class.java), options)
        finish()
    }
}